package edu.ccut.saturn.component.loader.data;

import java.util.List;

import org.dom4j.Element;

import edu.ccut.saturn.component.ISaturnDataSqlItemInfo;
import edu.ccut.saturn.component.impl.sql.IsEmptyItemInfo;

public class IsEmptyElementLoader extends AbstractSqlItemInfoLoader {

	@Override
	public ISaturnDataSqlItemInfo loadSqlItemInfo(Object element)
			throws Exception {

		if (element instanceof Element) {
			String prepend = ((Element) element)
					.attributeValue(NODE_KEY_PREPEND);

			String property = ((Element) element)
					.attributeValue(NODE_KEY_PROPERTY);

			IsEmptyItemInfo isEmptyItemInfo = new IsEmptyItemInfo(prepend,
					property);

			if (((Element) element).content().size() > 0) {
				List<ISaturnDataSqlItemInfo> sqlItemInfos = getSqlItemInfos(((Element) element)
						.content());

				isEmptyItemInfo.setSubSqlItemInfos(sqlItemInfos);
			}
			return isEmptyItemInfo;
		}
		return null;
	}

}
